package com.study.qqclient.service;

import com.study.qqcommon.Message;

import java.io.ObjectOutputStream;

/**
 * 文件传输
 * */
public class FileClientService {
    public static void sendFileToOne(String src, String dest, String senderId, String receiverId) {
        System.out.println("发送文件给" + receiverId);
        Message message = new Message();
        message.setSrc(src);
        message.setDest(dest);
        message.setSender(senderId);
        message.setGetter(receiverId);
        message.setMesType(Message.MESSAGE_FILE_MES);

        //获取文件，将文件转换为字节数组
        byte[] fileBytes = FileService.fileToByteArray(src);
        message.setFileBytes(fileBytes);
        message.setFileLen(fileBytes.length);

        //发送消息
        try {
            ObjectOutputStream oos = ManageClientContentServiceThread.getClientConnectServerThread(senderId).getOos();
            oos.writeObject(message);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
